<!DOCTYPE html>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script type="text/javascript" src="js/jquery-1.11.1.js"></script>
<title>添加客户</title>
<style type="text/css">
.test{
	width: 70%;
	margin-left: 15%;
}
.dec{
	margin-left: 10%;
	color: orange;
	line-height: 20pt;
}
.btn{
	margin-left: 30%;
	line-height: 20pt;
}
</style>
</head>
<body>
	<div>
		<form action="customer_add.action" method="post">
			<div>
				<span class="dec">账户：</span>
				<input type="text" id="username" name="username" /> <input type="hidden" id="btn_checkUsername" value="检查" onclick="checkUsername();" /> <input type="button" id="btn_check" value="check" />
			</div>
			<div>
				<span class="dec">密码：</span> <input type="text" id="password" name="password" />
			</div>
			<div class="btn">
				<input type="submit" value="提交" /> <input type="reset" value="重置" />
			</div>
		</form>

	</div>

</body>

<script type="text/javascript">
	function checkUsername() {
		var xmlhttp;
		if (window.XMLHttpRequest) {
			// code for IE7+, Firefox, Chrome, Opera, Safari
			xmlhttp = new XMLHttpRequest();
		} else {
			// code for IE6, IE5
			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		}
		xmlhttp.open("POST", "http://localhost:8080/restaurant/customer_exist.action", true);
		xmlhttp.onreadystatechange = function() {
			if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
				var result = xmlhttp.responseText;
				alert(result);
				//document.getElementById("checkResult").innerHTML = result;
			}
		}

		xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		var cname = document.getElementById("username").value;
		xmlhttp.send("username=" + cname);
	}
	$(document).ready(function() {
		$("#btn_check").click(function() {
			var cname = document.getElementById("username").value;
			$.post("customer_exist.action", {
				username : cname
			}, function(data, status) {
				var t = JSON.parse(data);
				alert("错误码:" + t.ErrorCode + "\n错误原因:" + t.ErrorReason);
				//alert("Data: " + data + "\nStatus: " + status);
			});
		});
	});
</script>
</html>
